﻿/******************************************************************************
 * Name         : PacketFactoryManager.hpp
 * Author       : 671643387
 * Date         : 2015年9月21日
 * Description  :
 *****************************************************************************/

#ifndef COMMON_PACKET_PACKETFACTORYMANAGER_HPP_
#define COMMON_PACKET_PACKETFACTORYMANAGER_HPP_

#include <boost/noncopyable.hpp>
#include <dev/base/Mutex.hpp>
#include <dev/base/LockedMap.hpp>
#include <common/packet/Packet.hpp>
#include <common/packet/PacketFactory.hpp>

namespace sxr
{
    namespace common
    {
        class PacketFactoryManager : public boost::noncopyable
        {
        public:
            PacketFactoryManager(void);
            ~PacketFactoryManager(void);

            static PacketFactoryManager* getMe(void);

        public:
            PacketPtr createPacket(int id);
            void addFactory(PacketFactoryPtr factory);
            void clean(void);

        private:
            typedef dev::base::LockedMap<int, PacketFactoryPtr, dev::base::NullMutex> FactoryMap;
            FactoryMap factories_;
        };
    }
}

#endif /* COMMON_PACKET_PACKETFACTORYMANAGER_HPP_ */
